#!/usr/bin/python

import re
import os

func = re.compile("gl[A-Z]\w*", re.MULTILINE)
const = re.compile("GL_[A-Z]+", re.MULTILINE)

srcdir="/home/andrew/gp2x/dev/gl2x/src"

def buildSupportedList():
    supported = {}
    for dirpath, dirnames, filenames in os.walk(srcdir):
        for filename in [f for f in filenames if f.endswith(".c")]:
            code = open(dirpath + os.sep + filename).read()
            for match in list(func.finditer(code)) + list(const.finditer(code)):
                supported[match.group(0)] = True
    return supported.keys()

def buildUsedList():
    used = {}
    for dirpath, dirnames, filenames in os.walk("./"):
        for filename in [f for f in filenames if f.endswith(".c")]:
            code = open(dirpath + os.sep + filename).read()
            for match in list(func.finditer(code)) + list(const.finditer(code)):
                used[match.group(0)] = True
    return used.keys()

def compare(supported, used):
    print "Unsupported functions and Constants"
    print "-----------------------------------"
    used.sort()
    for u in used:
        if u not in supported:
            print u

def main():
    supported = buildSupportedList()
    used = buildUsedList()
    compare(supported, used)

if __name__ == "__main__":
    main()
